package com.edison.demo.until;
import java.util.Random;

/**
 * @author edison
 */
public class EmailAddressGenerator {

    private EmailAddressGenerator(){
        throw new IllegalStateException("This is a utility class and cannot be instantiated");
    }

    private static final String LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String NUMBERS = "0123456789";
    private static final Random RANDOM = new Random();



    public static String generateRandomEmail() {
        String localPart = generateLocalPart();
        String domain = getRandomDomain();
        return localPart + "@" + domain;
    }

    private static String generateLocalPart() {
        StringBuilder localPart = new StringBuilder();
        int length = RANDOM.nextInt(6) + 5;

        for (int i = 0; i < length; i++) {
            if (RANDOM.nextBoolean()) {
                localPart.append(LETTERS.charAt(RANDOM.nextInt(LETTERS.length())));
            } else {
                localPart.append(NUMBERS.charAt(RANDOM.nextInt(NUMBERS.length())));
            }
        }

        return localPart.toString();
    }

    private static String getRandomDomain() {
        String[] popularDomains = {
                "gmail.com", "qq.com", "163.com", "outlook.com", "hotmail.com", "yahoo.com"
        };
        return popularDomains[RANDOM.nextInt(popularDomains.length)];
    }
}
